package util;

import java.util.List;
import java.util.Vector;


import orm.Course;
import orm.User;
import orm.UserDAO;

public class OnlineUsers {
	private static OnlineUsers users = new OnlineUsers();
    private Vector vector = null;
    public OnlineUsers()
    {
    	this.vector = new Vector();
    }
    public static OnlineUsers getInstance()
    {
    	return users;
    }
    public boolean addUser(User user)
    {
    	if(user!=null)
    	{
    		this.vector.add(user);
    		return true;
    	}
    	else return false;
    }
    public Vector getOnlineUsers()
    {
    	return vector;
    }
    public void removeUser(User user)
    {
    	if(user!=null)
    		vector.removeElement(user);
    }
    public Vector getMyTestingStus(User teacher,Course course)
    {
    	if(teacher==null||course==null)
    		return null;
    	UserDAO userdao = new UserDAO();
    	List res = userdao.getMyStu(teacher, course);
    	if(res==null)
    		return null;
    	Vector vec = new Vector();
    	for(int i=0;i<res.size();i++)
    	{
    		if(vector.contains(res.get(i)))
    		{
    			vec.add(res.get(i));
    		}
    	}
    	return vec;
   }
    
}
